/*
 * @Author: hejian@myhexin.com 
 * @Date: 2019-01-09 15:51:05 
 * @Last Modified by: hejian@myhexin.com
 * @Last Modified time: 2019-02-13 10:09:21
 */
$(function () {
	var vueInit = null;
	vueInit = new Vue({
		el: "#vuewrap",
		data: {
			androidApp: getPlatform() == 'gphone' ? true : false,
			detailTime: "2019-01-01",
			limitJlr:-1000000000000,
			wan: 10000,
			yi: 100000000,
			// 是否替代box-shadow
			isReplaceShadow: getPlatform() == "gphone" && (getOS().android - 0) < 6 ? true : false,
			// 排序标志位及参数
			number: 1, //1-21分别代表11种类型的升降序
			sortDirection: ["down", "", "", "", "", "", "", "", "", "", ""],
			defaultSort: {
				sort: "lbzs",
				lift: 1, //1降序 -1升序
				arr: "poolArr" //排序的数组
			},
			sortName: [{
				name: '连板数',
				sort: "lbzs",
			}, {
				name: '明日涨停概率',
				sort: "ztgl",
			}, {
				name: '涨停原因',
				sort: "ztyy",
			}, {
				name: '涨跌幅',
				sort: "upRise",
			}, {
				name: '最新价',
				sort: "price",
			}, {
				name: '换手率',
				sort: "hsl",
			}, {
				name: '龙虎榜净买入',
				sort: "jlr",
			}, {
				name: '成交额',
				sort: "cje",
			}, {
				name: '成交量',
				sort: "cjl",
			}, {
				name: '流通市值',
				sort: "ltsz",
			}, {
				name: '总市值',
				sort: "zsz",
			}],
			statSort: {
				lift: "desc",
				label: "lianban"
			},
			poolArr: [],
			poolArrEmpty: false,
			// 炸板池的排序标志位及参数
		},
		filters:{
			//用于数值或隐式数值类型
			textFilter:function (val,typeTag) {
				if(isNaN(val) || (!val && val != '0')){
					if(val && val != 'NaN'){
						return val
					}else{
						return '--'
					}
				}else{
					if(!typeTag){
						return val
					}else{
						return val + typeTag
					}
				}
			}
		},
		methods: {
			jumpFenshi: function (item, index) {
				var that = this;
				var code = item.stockcode;
				var marketid = item.marketcode;
				thsStats.jumpNativeStat('stockLimitDetail', that.statSort.label + "." + that.statSort.lift + "." + (index + 1), '2205', {
					targid: "stock_" + code
				});
				var url = "client.html?action=ymtz^stockcode=" + code + "^marketid=" + marketid + "^webid=2205"
				setTimeout(function () {
					location.href = url;
				}, 20);
			},
			// 请求涨停复盘的数据
			getSotckData: function () {
				var that = this;
				var that = this;
				var keyname = localStorage.getItem('__LASTDAYNAME__');
				var name = '__LIMITUPALLCOMPOUND__'
				var todayDetail = JSON.parse(localStorage.getItem(name));
				if (keyname) {
					that.detailTime = Jen.transNumToDate(keyname)
				}
				if (todayDetail) {
					for (var i = 0; i < todayDetail.length; i++) {
						if (!todayDetail[i].ztyy) {
							todayDetail[i].ztyy = "--"
						}
						if(!todayDetail[i].jlr){
							todayDetail[i].jlr=that.limitJlr
						}
					}
					that[that.defaultSort.arr] = todayDetail;
					that[that.defaultSort.arr].length != 0 && that[that.defaultSort.arr].sort(compare(that.defaultSort.sort, that.defaultSort.lift, 'stockcode'))
					if (that[that.defaultSort.arr].length == 0) {
						that.poolArrEmpty = true;
					}
					setTimeout(function () {
						that.listenDomEvent();
					}, 20)
				} else {
					that.poolArrEmpty = true;
				}
			},
			/**
			 * 
			 * @param {Number} index index 点击第index个
			 * @param {String} value value 第index个的排序关键字
			 * @param {String} arr 排哪个数组
			 * @param {String} lift 升降序数组
			 * @param {String} number 所有类型排序的标志位
			 * sort排序方式 1-(数组长度*2-1)分别代表种类型的升降序 偶数时升序，奇数是升序
			 */
			sort: function (index, value, arr, lift, number) {
				var that = this;
				var arr = that[arr];
				var lift = that[lift];
				for (var i = 0; i < lift.length; i++) {
					if (index == i) {
						if (!lift[i]) lift[i] = "up";
						if (lift[i] == "down") {
							lift[i] = "up";
							that[number] = i * 2;
						} else {
							lift[i] = "down";
							that[number] = (i * 2) + 1;
						}
						continue;
					} else {
						lift[i] = "";
					}
				}
				// 这个位置不能变
				var sort = that[number];
				var flag;
				if ((index * 2) + 1 == sort) {
					flag = 1;
				} else if (index * 2 == sort) {
					flag = -1
				}

				if ((value == 'price' || value == 'upRise') && !getAppVersion()) {
					return
				} else {
					if (value == "ztyy") {
						arr.length != 0 && that.sortHanzi(arr, value, flag)
					} else {
						arr.length != 0 && arr.sort(compare(value, flag, 'stockcode'))
					}

				}
				that.calcStats(value, flag);
			},
			calcStats: function (value, flag) {
				var that = this;
				var label, lift;
				switch (value) {
					case "lbzs":
						label = "lianban";
						break;
					case "ztgl":
						label = "ztgailv";
						break;
					case "ztyy":
						label = "ztyuanyin";
						break;
					case "upRise":
						label = "zhangdie";
						break;
					case "price":
						label = "zuixin";
						break;
					case "hsl":
						label = "huanshou";
						break;
					case "jlr":
						label = "jml";
						break;
					case "cje":
						label = "chengjiaoe";
						break;
					case "cjl":
						label = "chengjiao";
						break;
					case "ltsz":
						label = "liutong";
						break;
					case "zsz":
						label = "zongshizhi";
						break;
					default:
						break;
				}
				switch (flag) {
					case -1:
						lift = "asc";
						break;
					case 1:
						lift = "desc"
						break;
					default:
						break;
				}
				that.statSort['label'] = label;
				that.statSort['lift'] = lift;
				thsStats.clickStat("stockLimitDetail", label + "." + lift)
			},
			// 汉字排序 type：1从大到小 -1从小到大 arr数组 key关键字
			sortHanzi: function (arr, key, way) {
				arr.sort(function (a, b) {
					if (a[key] && b[key]) {
						return -compareInPinYin(a[key], b[key]) * way
					}
				})
			},
			listenDomEvent: function () {
				// 涨停复盘的哪个list
				var $list = $(".limitStockDetail  .list");
				var dpr = $("html").data("dpr") ? $("html").data("dpr") : 1;
				var bittomd1 = true;
				if (this.isReplaceShadow) {
					var shadowName = "replaceShadow"
				} else {
					var shadowName = "shadow"
				}
				$list.find(".list-r").on('scroll', function () {
					if ($(this).scrollLeft() > 0) {
						$(this).parent().find('.list-l').addClass(shadowName)
						$(this).parent().find(".smallTriangle").hide();
					} else {
						$(this).parent().find('.list-l').removeClass(shadowName)
						$(this).parent().find(".smallTriangle").show();
					}
				})
				// 滚动到底部埋点
				$(window).on('scroll', function () {
					var windowHeight =
						getPlatform() == "iphone" ?
						window.screen.height :
						$(window).height(); //window高度
					var totalHeight = $(document).height() / dpr; //页面总高度
					var scrollHeight = $(window).scrollTop() / dpr; //window距顶部距离
					if (
						(scrollHeight + 10 >= totalHeight - windowHeight) &&
						scrollHeight != 0
					) {
						if (bittomd1) {
							thsStats.clickStat('stockLimitDetail', 'bottom')
							bittomd1 = false;
						}
					}
				})

			}
		},
		mounted: function () {
			thsStats.pageStat('stockLimitDetail')
			var that = this;
			setTimeout(function () {
				that.getSotckData();
			}, 20)
		}
	})
})